using System;
using System.Data;
using System.Data.SqlClient;

using PHSRAG.Insight21.BusinessObjects;
using ICachePolicy = PHSRAG.Insight21.Policy.ICachePolicy;

namespace PHSRAG.Insight21.ClinicalTrials
{
   /// <summary>
   /// The BudgetStaff class is the facade over a single Budget Staff
   /// </summary>
   public class BudgetStaff : BusinessObject
   {

      #region Constants
      private const string BudgetStaffKey = "BudgetStaff_F52323F3-AE23-4135-BE10-4006E4B47755";
      private const string TableName = "BudgetStaff";
      #endregion

      #region Instance Variables
      private DataRow dataRow;
      #endregion

      #region Public Properties
      /// <summary>
      /// Unique Id for this Budget Staff
      /// </summary>
      public int Id
      {
         // We need to test whether the staff is saved in the budget tabs control
         // so we supply a valid int when the staff is new
         get
         {
            object o = dataRow["Id"];
            return (o == DBNull.Value) ? 0 : (int)o;
         }
      }

      /// <summary>
      /// Budget relate id
      /// </summary>
      public int BudgetId
      {
         get
         {
            return (int)dataRow["ClinicalTrialBudgetId"];
         }
         set
         {
            dataRow["ClinicalTrialBudgetId"] = value;
         }
      }

      /// <summary>
      /// Study staff role code
      /// </summary>
      public string StudyStaffRoleCode
      {
         get
         {
            return dataRow["StudyStaffRoleCode"].ToString( );
         }
         set
         {
            dataRow["StudyStaffRoleCode"] = value;
         }
      }

      /// <summary>
      /// Study staff role meaning.
      /// Used to load the staff dropdown on the Visits page
      /// We need the set, even though we don't persist it 
      /// so it carries over to the visits tab if you made
      /// a change.
      /// </summary>
      public string StudyStaffRoleMeaning
      {
         get
         {
            string roleMeaning = dataRow["StudyStaffRoleMeaning"].ToString( );
            if ( roleMeaning == "Other" )
            {
               return OtherRoleText;
            }
            return roleMeaning;
         }
         set
         {
            dataRow["StudyStaffRoleMeaning"] = value;
         }
      }

      /// <summary>
      /// Other role text
      /// </summary>
      public string OtherRoleText
      {
         get
         {
            return dataRow["OtherRoleText"].ToString( );
         }
         set
         {
            dataRow["OtherRoleText"] = value;
         }
      }

      /// <summary>
      /// Rate for this Staff
      /// </summary>
      public string Rate
      {
         get
         {
            object o = dataRow["Rate"];
            return (o == DBNull.Value) ? null : o.ToString( );
         }
         set
         {
            dataRow["Rate"] = value;
         }
      }
      #endregion

      #region Constructor
      /// <summary>
      /// Initialize the base class with the specified cache policy and sets the dataRow member.
      /// </summary>
      public BudgetStaff( ICachePolicy cachePolicy, DataRow row ) : base ( cachePolicy )
      {
         dataRow = row;
      }
      #endregion

      #region Base Methods
      /// <summary>
      /// Cache this instance using the prevalent cache policy.
      /// </summary>
      public override void Cache( )
      {
         CachePolicy.Cache( BudgetStaffKey, this );
      }

      /// <summary>
      /// Remove this instance from the cache using the prevalent cache policy.
      /// </summary>
      public override void UnCache( )
      {
         CachePolicy.UnCache( BudgetStaffKey );
      }

      /// <summary>
      /// Load method is not used
      /// </summary>
      /// <param name="connectionString"></param>
      /// <param name="args"></param>
      public override void Load( string connectionString, params object[] args )
      {
         throw new Exception("BudgetStaff is not directly loadable");
      }
      #endregion

   }// END CLASS DEFINITION BudgetStaff
}